#!/bin/bash

# Everything has to succeed
set -o errexit
set -o pipefail
set -o nounset

tin() {
  _tmp/deps/tin.tin "$@"
}

build-python-lib() {
  local version=none  # TODO: add version

  # Make a zip file
  mkdir -p _tmp/py
  pushd _tmp/py >/dev/null
  cp --verbose ../../python/tnet.py .
  cp --verbose ../../README .
  zip tnet-python.zip *.py README
  popd >/dev/null

  # Then copy it to $CDI_OUT
  mkdir -p _tmp/out
  cp --verbose _tmp/py/tnet-python.zip $CDI_OUT

  tree $CDI_OUT
}

readonly pypath=.:$CDI_DEPS/simplejson-2.6.2 

# TODO:
# - tnet tool should be a Basis package
# - what about the Python library?  Look at pgi.py and hogR, etc.

Build() {
  # Build the tnet tool.  Set PYTHONPATH so it can import.
  PYTHONPATH=$pypath tin build-python bin.tnet

  build-python-lib
}

Test() {
  # TODO: hook up the tests for other languages.
  ./run.sh py-unit-test
}

Deploy() {
  scp -v tnet.tin $CDI_DEPLOY_DEST/tnet/latest/
  scp -v $CDI_OUT/tnet-python.zip $CDI_DEPLOY_DEST/tnet/latest/

  # TODO: deploy library for each language too.
}

"$@"
